package esms.action.impl;

import org.apache.log4j.Logger;

import com.thoughtworks.selenium.DefaultSelenium;

import esms.action.ActionInterface;

public class Login implements ActionInterface {
	private String url;
	private String userId;
	private String password;
	private static Logger log = Logger.getLogger("LoginAction");

	public static final String USER_NAME_PATH = "//input[@id='userid']";
	public static final String USER_PASSWORD_PATH = "//input[@id='password']";
	public static final String SIGN_IN_PATH = "//input[@name='signIn']";
	
	public Login(String url, String userId, String password) {
		this.url = url;
		System.out.println(this.url);
		this.userId = userId;
		this.password = password;
	}

	public void execute(DefaultSelenium selenium) {
		try {
			selenium.open(this.url);
			selenium.type(USER_NAME_PATH, userId);
			selenium.type(USER_PASSWORD_PATH, password);
			selenium.clickAt(SIGN_IN_PATH, "");
		} catch (Exception e) {
			log.error(e);
		}
	}
}
